package com.itheima.xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws DocumentException {
        ArrayList<Student> list = new ArrayList<>();
        SAXReader reader = new SAXReader();
        Document doc = reader.read(new File("day18_XML&枚举&注解\\xml\\demo.xml"));
        Element e = doc.getRootElement();
        List<Element> elements = e.elements("student");
        for (Element el : elements) {
            Attribute value = el.attribute("id");
            String id = value.getValue();
            Element elName = el.element("name");
            String name = elName.getText();
            Element elAge = el.element("age");
            String age = elAge.getText();
            int i = Integer.parseInt(age);

            Student s = new Student(id,name,i);
            list.add(s);
        }
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
